home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pcroct89.arc / PCTOCT.ARC / PRTSCR2.C < prev   
C/C++ Source or Header  |  1990-03-21  |  8KB  |  286 lines

  1. /* C routines for PrtScr program.
  2.  *   This file contains the routines that read from the screen
  3.  *   and format data for output to the printer.
  4.  *
  5.  * Save this files as PRTSCR2.C.
  6.  * Compile:   cl /c /Gs Prtcrs2.c                    (MSC 5.1)
  7.  *         or:  qcl /c /Gs Prtscr2.c                    (QUICKC 2.0)
  8.  *    plus:  link /NOD Prtscr1 Prtscr2,Prtscr;  (MS Link)
  9.  *
  10.  *      or:  tcc -N- -c Prtscr2.c                    (TC 2.0)
  11.  *         tlink /n/c Prt2cr1 Prtscr2,PrtScr    (TLINK)
  12.  */
  13.  
  14. /* These definitions are from MSC/QC DOS.H file: */
  15.  
  16. #define FP_SEG(fp) (*((unsigned *)&(fp) + 1))
  17. #define FP_OFF(fp) (*((unsigned *)&(fp)))
  18.  
  19. /* function prototypes: */
  20. void textmode(void);
  21. void lo_res(void);
  22. void med_res(void);
  23. void hi_res(void);
  24. void prt_string(char *s);
  25. extern void gc_out(int index, int value);
  26. extern void prt_out(int ch);
  27. int cga_4(int x, int y);
  28. int cga_6(int x, int y);
  29. int ega_clr(int x, int y);
  30. int ega_mono(int x, int y);
  31.  
  32. /* External global data */
  33. extern int vidmode, vidcols, vidrows;
  34. extern int vidseg,  vidoff;
  35.  
  36. int bytes;                                /* EGA graphics bytes-per-row */
  37.  
  38. /* textmode puts the screen at the current
  39.    printhead location.  It uses wide print
  40.     if 40 columns or less are displayed, and
  41.     condensed print if more than 80 columns are
  42.     displayed.
  43. */
  44.  
  45. void textmode()
  46. {
  47.     int far *textposn;
  48.     int x,y;
  49.     int bkgrnd, frgrnd;
  50.     int ch;
  51.     int vidword;
  52.  
  53.     if (vidcols > 80)
  54.         prt_out(0x0f);                            /* start condensed mode */
  55.     if (vidcols <= 40)
  56.         prt_string("\x1bW\x01");            /* start expanded mode  */
  57.     FP_SEG(textposn) = vidseg;
  58.     FP_OFF(textposn) = vidoff;
  59.     for (y = 0; y <= vidrows; y++)        /* For each row... */
  60.         {
  61.         for (x = 1; x <= vidcols; x++)    /* For each column ... */
  62.             {
  63.             vidword = *textposn++;            /* Get char. & attribute */
  64.             bkgrnd = vidword >> 12;
  65.             frgrnd = (vidword >> 8) & 0xf;
  66.             if (bkgrnd != frgrnd)           /* Don't show 'hidden' chars. */
  67.                 {
  68.                 ch = vidword & 0xff;
  69.                 prt_out(ch);
  70.                 }
  71.             else
  72.                 prt_out(' ');
  73.             }
  74.         prt_string("\x0d\x0a");               /* Carriage return/line feed */
  75.         }
  76.     if (vidcols > 80)
  77.         prt_out(0x12);                           /* Cancel condensed mode */
  78.     if (vidcols <= 40)
  79.         {
  80.         prt_string("\x1bW");                   /* Cancel expanded mode  */
  81.         prt_out(0);
  82.         }
  83. }
  84.  
  85.  
  86. /* The graphics routines assume that the printhead is at the top
  87.    of a page -- they center the image between top/bottom and
  88.     left/right page edges
  89. */
  90.  
  91. void lo_res(void)                                /* 320 x 200 modes */
  92. {
  93.     int (*get_pixel) (int x, int y);        /* Function prototype */
  94.     int x,y,i;
  95.     int bkgrnd;
  96.     int printbyte;
  97.  
  98.     if(vidmode < 6)                            /* Select get_pixel function: */
  99.         get_pixel = cga_4;                   /* CGA mode 4 */
  100.     else
  101.         {
  102.         get_pixel = ega_clr;                    /* or EGA color, 40-col mode  */
  103.         bytes = 40;
  104.         }
  105.     bkgrnd = get_pixel(0,0);            /* This color will print 'white' */
  106.     prt_string("\x0d\x1b\x33\x18");    /* Set 24/216 (8/72) line feeds  */
  107.     for (i = 0; i < 10; i++)
  108.         prt_out(0x0a);
  109.  
  110.     for (x = 319; x >= 3; x -=4)
  111.         {
  112.         prt_string("\x1bK\xb8\x01");    /* Ready to print 0x1B8 (440) chars. */
  113.         for (i = 0; i < 40; i++)
  114.             prt_out(0);                        /* 40 blanks make a margin    */
  115.         for (y = 0; y < 200; y++)
  116.             {
  117.             printbyte = 0;                    /* Each byte represents 4 vid. cols. */
  118.             for (i = 0; i < 4; i++)
  119.                 {
  120.                 printbyte <<= 2;              /* Shift old value left, then ... */
  121.                 if (get_pixel(x-i,y) != bkgrnd)
  122.                     printbyte |= 3;        /* Add 0000 0011 if not bkgrnd color */
  123.                 }
  124.             prt_out(printbyte);            /* Send byte to printer twice */
  125.             prt_out(printbyte);
  126.             }
  127.         prt_string("\x0d\x0a");            /* Carriage return/line feed */
  128.         }
  129.     prt_out(0x0c);                            /* End with a form feed */
  130.     prt_string("\x1b\x32");                /* Cancel short line feeds */
  131. }
  132.  
  133. void med_res(void)                        /* 640 x 200 modes */
  134. {
  135.     int (*get_pixel) (int x, int y);
  136.     int x,y,i;
  137.     int bkgrnd;
  138.     int printbyte;
  139.  
  140.     if (vidmode == 6)                        /* Select get_pixel function */
  141.         get_pixel = cga_6;                /* CGA mode 6 or */
  142.     else
  143.         {
  144.         get_pixel = ega_clr;                /* EGA 80-column mode */
  145.         bytes = 80;
  146.         }
  147.  
  148.     bkgrnd = get_pixel(0,0);
  149.     prt_string("\x0d\x1b\x33\x18");    /* Set 8/72 line feeds */
  150.     for (i = 0; i < 10; i++)
  151.         prt_out(0x0a);                        /* Top margin */
  152.  
  153.     for (x = 639; x >= 7; x -= 8)
  154.         {
  155.         prt_string("\x1bK\xb8\x01");    /* Ready for 440 graphics chars. */
  156.         for (i = 0; i < 40; i++)
  157.             prt_out(0);                        /* Margin of 40 blanks                */
  158.         for (y = 0; y < 200; y++)
  159.             {
  160.             printbyte = 0;                    /* Clear output byte */
  161.             for (i = 0; i < 8; i++)        /* Each byte represents 8 video cols. */
  162.                 {
  163.                 printbyte <<= 1;            /* Shift old value left */
  164.                 if (get_pixel(x-i,y) != bkgrnd)
  165.                     printbyte |= 1;        /* Add 0000 0001 if not bkgrnd color */
  166.                 }
  167.             prt_out(printbyte);            /* Send byte out twice */
  168.             prt_out(printbyte);
  169.             }
  170.         prt_string("\x0d\x0a");            /* Carriage return & line feed */
  171.         }
  172.     prt_out(0x0c);                            /* End with form feed */
  173.     prt_string("\x1b\x32");                /* Cancel short line feeds */
  174. }
  175.  
  176.  
  177. void hi_res(void)                            /* 640 x 350 video modes */
  178. {
  179.     int (*get_pixel) (int x, int y);
  180.     int x,y,i;
  181.     unsigned bkgrnd;
  182.     unsigned printbyte;
  183.  
  184.     if (vidmode == 0x0f)
  185.         get_pixel = ega_mono;            /* EGA monochrome mode or ... */
  186.     else
  187.         get_pixel = ega_clr;                /* EGA 80-col color mode */
  188.     bytes = 80;
  189.  
  190.     bkgrnd = get_pixel(0,0);
  191.     prt_string("\x0d\x1b\x33\x15");    /* Set up 21/216 line feeds */
  192.     for (i = 0; i < 16; i++)
  193.         prt_out(0x0a);                        /* Top margin */
  194.  
  195.     for (x = 639; x >= 7; x -= 8)
  196.         {
  197.         prt_string("\x1bK\x9f\x01");    /* Ready for 415 graphics chars */
  198.         for (i = 0; i < 65; i++)
  199.             prt_out(0);                        /* 65 blanks for margin */
  200.         for (y = 0; y <= 349; y++)
  201.             {
  202.             printbyte = 0;                    /* Clear output byte */
  203.             for (i = 0; i < 8; i++)
  204.                 {
  205.                 printbyte <<= 1;            /* Shift old value to left */
  206.                 if (bkgrnd != get_pixel(x-i,y))
  207.                     printbyte |= 1;        /* Add 0000 0001 if not bkgrnd color */
  208.                 }
  209.             prt_out(printbyte);            /* Send it out */
  210.             }
  211.         prt_string("\x0d\x0a");            /* Carriage return, line feed */
  212.         }
  213.     prt_out(0x0c);                            /* End with a form feed */
  214.     prt_string("\x1b\x32");                /* Cancel short line feeds */
  215. }
  216.  
  217.  
  218. int cga_4(int x, int y)            /* Read one pixel from CGA mode 4 & 5 */
  219. {
  220.     char byte;
  221.     char far *vid;
  222.     
  223.     FP_SEG(vid) = 0xb800;
  224.     FP_OFF(vid) = vidoff + 0x2000 * (y%2) + 80 * (y/2) + x/4;
  225.     byte = *vid;
  226.     return (byte >> (6 - (x%4)*2) & 3);
  227. }
  228.  
  229. int cga_6(int x, int y)            /* Read one pixel from CGA mode 6 */
  230. {
  231.     char byte;
  232.     char far *vid;
  233.     FP_SEG(vid) = 0xb800;
  234.     FP_OFF(vid) = vidoff + 0x2000 * (y%2) + 80 * (y/2) + x/8;
  235.     byte = *vid;
  236.     return  (byte >> (7 - (x%8)) & 1);
  237. }
  238.  
  239.  
  240. int ega_clr(int x, int y)        /* Read one pixel from EGA color screen  */
  241. {                                        /* Note: doesn't work with 64K EGA board */
  242.     char mask;
  243.     char far *vid;
  244.     int i, color;
  245.  
  246.     FP_SEG(vid) = 0xa000;
  247.     FP_OFF(vid) = y * bytes + x / 8 + vidoff;
  248.     mask = (char)(0x80 >> (x % 8));        /* Select bit position to read */
  249.     color = 0;
  250.     gc_out(5,0);                                /* select read mode 0 */
  251.     for (i = 3; i >= 0; i--)
  252.         {
  253.         color <<= 1;                            /* Merge all 4 color bits */
  254.         gc_out(4,i);
  255.         if (*vid & mask)
  256.             color |= 1;
  257.         }
  258.     return color;
  259. }
  260.  
  261. int ega_mono(int x, int y)        /* Read one pixel from EGA mono screen */
  262. {
  263.     char mask;
  264.     char far *vid;
  265.     int color;
  266.  
  267.     FP_SEG(vid) = 0xa000;
  268.     FP_OFF(vid) = y * bytes + x/8 + vidoff;
  269.     mask = (char)(0x80 >> (x % 8));
  270.     color = 0;
  271.     gc_out(5,0);
  272.     gc_out(4,0);
  273.     if (*vid & mask)
  274.         color |= 1;
  275.     gc_out(4,2);
  276.     if (*vid & mask)
  277.         color |= 2;
  278.     return color;
  279. }
  280.  
  281. void prt_string(char *s)            /* Send a string to the printer */
  282. {
  283.     while (*s)
  284.         prt_out(*s++);
  285. }
  286.